
package vm.project;

import com.googlecode.jcsv.reader.CSVReader;
import com.googlecode.jcsv.reader.internal.CSVReaderBuilder;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import jxl.read.biff.BiffException;

public class Donnees {
    public ArrayList<Point> init(){
        ArrayList<Point> tab = new ArrayList<>();
        tab.add(new Point(0, 0, 0, 2));
        tab.add(new Point(3, 3, 1, 2));
        return tab;
    }

    public ArrayList<Point> lireCSV(String fichier,GestionStations gs, int dataNum) throws FileNotFoundException, IOException{
        ArrayList<Point> tabPoint = new ArrayList<>();
        Reader reader = new FileReader(fichier);

        CSVReader<String[]> csvParser = CSVReaderBuilder.newDefaultReader(reader);
        List<String[]> data = csvParser.readAll();
        boolean enCour = false;

        for (String[] oneData : data) {
            
            if(enCour && oneData[0].equals("")){
                enCour=false;
            }
            if(oneData.length>0 && enCour){
                String normalise = oneData[0].split(" - ")[0];
                Point prov = new Point(gs.getXof(normalise),gs.getYof(normalise),Double.parseDouble(oneData[dataNum]),2);
                tabPoint.add(prov);
            }
            
            if(oneData.length>0 && oneData[0].startsWith("        Is")){
                enCour=true;
            }
        }
        return tabPoint;
    }


}
